#ifndef PROJECT_C_
#define PROJECT_C_

#include <stdio.h>
#include <sys/types.h>

#define new(type) 	((type*)calloc(sizeof(type), 1))
#define MAX(x,y)	((x) > (y) ? (x) : (y))

/* 文件数据块缓存 */
struct f_buf
{
	char *block_buf;
	struct f_buf *next;
};
typedef struct f_buf * F_BUF;

/* 文件信息,此ADT将使用二叉树组合 */
struct f_file
{
	char *fl_name;
	u_int32_t fl_count;				//文件被读取次数
	time_t last_access;				//上次文件被读取的时间
	u_int64_t fl_size;				//文件大小
	struct f_buf *fl_buf;
	struct f_file *left;
	struct f_file *right;
};
typedef struct f_file * F_FILE;

/* hash表 */
struct f_hash
{
	u_int32_t ha_file_count;				//此节点总共拥有的文件数
	u_int64_t ha_size;						//此节点所有文件大小总和
	struct f_file *ha_file;
};
typedef struct f_hash * F_HASH;

/************************************************/
extern u_int64_t ALL_BUFFER_SIZE;
extern char *FILEPATH;
extern char *PROFILEPATH;
extern char *BACKFILE;
extern u_int32_t HASH_TABLE_SIZE;
extern u_int32_t BLOCK_SIZE;
extern u_int32_t FILENAME_LENGTH;
extern u_int32_t SECTION_LENGTH;
extern u_int32_t BUFFER_FILE_SIZE;
extern u_int32_t BUFFER_INVALID_TIME;
extern u_int32_t BACKUP_TIME;
extern u_int64_t MAX_BUFFER_SIZE;

extern F_HASH f_hash_arr;
extern long get_file_size(const char*);
extern int f_read(char**,int);
extern F_FILE checkIfCache(long,int,char*);
extern size_t atom_read(FILE*, char*, size_t);
/************************************************/

#endif		
//END OF PROJECT_C_